<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">






  
  
  <link rel="stylesheet" media="all" href="/lib/Han/dist/han.min.css?v=3.3">




<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/favicon.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon.png?v=5.1.4">


  <link rel="mask-icon" href="/images/favicon.png?v=5.1.4" color="#222">





  <meta name="keywords" content="模式识别," />





  <link rel="alternate" href="/atom.xml" title="平步青云win" type="application/atom+xml" />






<meta name="description" content="统计模式识别分为聚类分析和判别函数法两大类，聚类分析属于非监督分类，判别函数法属于监督分类。判别函数法需要有足够的先验知识，首先利用已知类别的训练样本集确定判别函数，然后利用训练好的判别函数对未知的模式进行识别分类">
<meta name="keywords" content="模式识别">
<meta property="og:type" content="article">
<meta property="og:title" content="模式识别(三)--判别函数及几何分类法">
<meta property="og:url" content="https://zxpgo.github.io/2018/11/08/模式识别(三)--判别函数及几何分类法/index.html">
<meta property="og:site_name" content="平步青云win">
<meta property="og:description" content="统计模式识别分为聚类分析和判别函数法两大类，聚类分析属于非监督分类，判别函数法属于监督分类。判别函数法需要有足够的先验知识，首先利用已知类别的训练样本集确定判别函数，然后利用训练好的判别函数对未知的模式进行识别分类">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="https://i.imgur.com/45CWBgs.png">
<meta property="og:image" content="https://i.imgur.com/aufZhLj.png">
<meta property="og:image" content="https://i.imgur.com/geD5PCG.png">
<meta property="og:image" content="https://i.imgur.com/OrGRvyT.png">
<meta property="og:image" content="https://i.imgur.com/r5NdfVC.png">
<meta property="og:image" content="https://i.imgur.com/Tlka5WK.png">
<meta property="og:image" content="https://i.imgur.com/HdQnVrQ.png">
<meta property="og:image" content="https://i.imgur.com/OMAhPvH.png">
<meta property="og:image" content="https://i.imgur.com/x6Nlep4.png">
<meta property="og:updated_time" content="2018-11-09T06:55:49.026Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="模式识别(三)--判别函数及几何分类法">
<meta name="twitter:description" content="统计模式识别分为聚类分析和判别函数法两大类，聚类分析属于非监督分类，判别函数法属于监督分类。判别函数法需要有足够的先验知识，首先利用已知类别的训练样本集确定判别函数，然后利用训练好的判别函数对未知的模式进行识别分类">
<meta name="twitter:image" content="https://i.imgur.com/45CWBgs.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"right","display":"post","offset":10,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: 'PAO8LM7QB1',
      apiKey: '',
      indexName: 'Blog',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://zxpgo.github.io/2018/11/08/模式识别(三)--判别函数及几何分类法/"/>





  <title>模式识别(三)--判别函数及几何分类法 | 平步青云win</title>
  





  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?7a4517a3ce6d7c50203655d056f01ac3";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-right page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">平步青云win</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <h1 class="site-subtitle" itemprop="description"></h1>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-随笔">
          <a href="/sui" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-question-circle"></i> <br />
            
            随笔
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
			
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off"
             placeholder="搜索..." spellcheck="false"
             type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://zxpgo.github.io/2018/11/08/模式识别(三)--判别函数及几何分类法/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="zxp">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="平步青云win">
    </span>

    
      <header class="post-header">

        
        
          <h2 class="post-title" itemprop="name headline">模式识别(三)--判别函数及几何分类法</h2>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-11-08T19:02:50+08:00">
                2018-11-08
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/模式识别/" itemprop="url" rel="index">
                    <span itemprop="name">模式识别</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          
             <span id="/2018/11/08/模式识别(三)--判别函数及几何分类法/" class="leancloud_visitors" data-flag-title="模式识别(三)--判别函数及几何分类法">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数&#58;</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body han-init-context" itemprop="articleBody">

      
      

      
        <p>统计模式识别分为聚类分析和判别函数法两大类，聚类分析属于非监督分类，判别函数法属于监督分类。判别函数法需要有足够的先验知识，首先利用已知类别的训练样本集确定判别函数，然后利用训练好的判别函数对未知的模式进行识别分类<a id="more"></a></p>
<p>判别函数，又可以分为线性判别函数法，非线性判别函数和统计决策方法。其中线性判别函数和非线性判别函数法是几何分类法，用户研究确定性事件的识别非零。统计决策方法是概率分类法，用于研究随机事件的识别分类。</p>
<p><img src="https://i.imgur.com/45CWBgs.png" alt=""></p>
<h2 id="3-1-判别函数"><a href="#3-1-判别函数" class="headerlink" title="3.1 判别函数"></a>3.1 判别函数</h2><p>模式识别系统的主要作用是判别各个模式的所在类别。</p>
<p>若分属于ω1，ω2的两类模式可用一方程d(X)=0来划分，那么称d(X)为判别函数或称判决函数、决策函数。</p>
<p>例：一个二维的两类判别问题,模式分布如图示，这些分属于ω1，ω2两类的模式可用一直线方程d(X)=0来划分。</p>
<p><img src="https://i.imgur.com/aufZhLj.png" alt=""></p>
<p>$d(X)=w_1x_1+w_2x_2+w_3=0$</p>
<p>式中：$x_1,x_2$为坐标向量，$w_1,w_2,w_3$为方程参数。</p>
<ul>
<li>如果$d(X)&gt;0$，则$X \in w_1$类；</li>
<li>如果$d(X)&lt;0$，则$X \in w_2$类；</li>
<li>如果$d(X)=0$，则$X \in w_1$或$X \in w_2$类或拒绝。</li>
</ul>
<p>维数=3是：判别边界是一平面。维数&gt;3时，判别边界为一超平面。</p>
<h2 id="3-2-线性判别函数"><a href="#3-2-线性判别函数" class="headerlink" title="3.2 线性判别函数"></a>3.2 线性判别函数</h2><p>如果一些模式类能用线性判别函数分开，则称这些模式类是线性可分的。</p>
<h3 id="3-2-1-线性判别函数的一般形式"><a href="#3-2-1-线性判别函数的一般形式" class="headerlink" title="3.2.1 线性判别函数的一般形式"></a>3.2.1 线性判别函数的一般形式</h3><p>将二维模式推广到n维，线性判别函数的一般形式为：</p>
<p>$d(X) = w_1x_1+w_2x_2+\dots+w_nx_n+w_{n+1}=W_0^TX+w_{n+1}$</p>
<p>式中：$X=[x_1,x_2,\dots,x_n]^T$，$W_0=[w_1,w_2,\dots,w_n]^T$；$W_0$是权向量，即参数向量。</p>
<p>增广向量形式：</p>
<p>$d(X)=w_1x_1+w_2x_2+\dots+w_nx_n+w_{n+1} \cdot 1 = [w_1,w_2,\dots,w_n, w_{n+1}][x_1,x_2,\dots,x_n,1]^T = W^TX$</p>
<p>式中：$X=[x_1,x_2,\dots,x_n,1]^T$，$W_0=[w_1,w_2,\dots,w_n,w_{n+1}]^T$为增广权向量。</p>
<h3 id="3-2-1-线性判别函数的性质"><a href="#3-2-1-线性判别函数的性质" class="headerlink" title="3.2.1 线性判别函数的性质"></a>3.2.1 线性判别函数的性质</h3><h4 id="1-两类情况"><a href="#1-两类情况" class="headerlink" title="1.两类情况"></a>1.两类情况</h4><p>若已知两类模式$w_1,w_2$，则判别函数$d(X)=W^TX$，具有如下性质：</p>
<p><img src="https://i.imgur.com/geD5PCG.png" alt=""></p>
<p>$d(x)=0$是不可分情况。</p>
<h4 id="2-多类情况"><a href="#2-多类情况" class="headerlink" title="2.多类情况"></a>2.多类情况</h4><p>对$M$个线性可分模式类，$w_1,w_2,\dots,w_M$，有三种划分方式：</p>
<ul>
<li>$w_i/\bar{w_i}$两分法</li>
<li>$w_i/w_j$两分法</li>
<li>$w_i/w_j$两分法特例</li>
</ul>
<h5 id="w-i-bar-w-i-两分法"><a href="#w-i-bar-w-i-两分法" class="headerlink" title="$w_i/\bar{w_i}$两分法"></a>$w_i/\bar{w_i}$两分法</h5><p>用线性判别函数将属于$w_i$类的模式与其余不属于$w_i$类的模式分开。</p>
<p><img src="https://i.imgur.com/OrGRvyT.png" alt=""></p>
<p>将某个待分类模式$X$分别代入$M$个类的$d(X)$中，若只有$d_i(X)&gt;0$，其他$d(X)$均$&lt;0$，则判为$ω_i$类。</p>
<p>对某一模式区，$d_i(X)&gt;0$的条件超过一个，或全部的$d_i(X)&lt;0$，分类失效。相当于不确定区(indefinite region ，IR)。</p>
<p><img src="https://i.imgur.com/r5NdfVC.png" alt=""></p>
<h5 id="w-i-w-j-两分法"><a href="#w-i-w-j-两分法" class="headerlink" title="$w_i/w_j$两分法"></a>$w_i/w_j$两分法</h5><p>一个判别界只能分开两个类别，不能把其余所有的类别都分开。能够分开$w_i$类和$w_j$类的判别函数为：$d_{ij}(X)=W_{ij}^TX$，这里$d_{ij}=-d_{ji}$。</p>
<p>判别函数性质：</p>
<p>$d_{ij}(X)&gt;0, \forall j \neq i, i,j = 1,2,\dots, M$，若$X \in w_i$</p>
<p>在$M$类模式中，与$i$有关的$M-1$个判决函数全为正时，$X \in ωi$。其中若有一个为负，则为IR区。</p>
<p>$w_i/w_j$两分法每分离出一个模式，需要$M-1$个判别函数，而要分离所有的$M$类模式，共需要$M(M-1)/2$个判别函数。</p>
<h4 id="w-i-w-j-两分法特例"><a href="#w-i-w-j-两分法特例" class="headerlink" title="$w_i/w_j$两分法特例"></a>$w_i/w_j$两分法特例</h4><p>当$w_i/w_j$两分法中的判别函数$d_{ij}(X)$，可以分解为：$d_{ij}(X)=d_i(X)-d_j(X)$时，那么$d_i(X) &gt; d_j(X)$相当于多累情况2中的$d_{ij}(X)&gt;0$。</p>
<p>因此，具有判别函数：$d_i(X)=W^T_iX, i=1,\dots,M$的$M$类情况，判别函数性质为：</p>
<p>$d_i(X) &gt; d_j(X)  \forall j \neq i, i,j = 1,2,\dots, M$ 若$X \in w_i$</p>
<p>或 $d_i(X) \max{\lbrace d_k(X), k= 1,2,\dots, M \rbrace} $ 若$X \in w_i$</p>
<h2 id="3-3-广义线性判别函数"><a href="#3-3-广义线性判别函数" class="headerlink" title="3.3 广义线性判别函数"></a>3.3 广义线性判别函数</h2><p>对非线性边界：通过某映射，把模式空间X变成$X^{\ast}$，以便将X空间中非线性可分的模式集，变成在$X^{\ast}$空间中线性可分的模式集。</p>
<h3 id="1-非线性多项式函数"><a href="#1-非线性多项式函数" class="headerlink" title="1. 非线性多项式函数"></a>1. 非线性多项式函数</h3><p>非线性判别函数的形式之一是非线性多项式函数。 设一训练用模式集$\lbrace x \rbrace$，在模式空间$X$中线性不可分，非线性判别函数形式如下：</p>
<p>$d(X)=w_1f_1(X)+w_2f_2(X)+\dots+w_kf_k(X)+w_{+1} = \sum_{i=1}^{k+1}w_if_i(X)$</p>
<p>其中$\lbrace f_i(X),i=1,2,\dots,k \rbrace$是模式$X$的单值函数，$f_{k+1}(X)=1$。</p>
<p>广义形式的模式向量为：</p>
<p>$X^{\ast}=[x_1^{\ast}.x_2^{\ast},\dots,x_k^{\ast},1]^T=[f_1(X),f_2(X),\dots,f_k(X),1]^T$</p>
<p>这里$X^{\ast}$空间的维数$k$高于$X$空间的维数$n$。$d(X)$可以改写为：</p>
<p>$d(X) = W^TX^{\ast}=d(X^{\ast}), W=[w_1,w_2,\dots,w_k,w_{+1}]^T$</p>
<p>上式是线性的。讨论线性判别函数并不会失去一般性的意义。</p>
<p><strong>问题</strong></p>
<p>非线性变换可能非常复杂 。</p>
<p>维数大大增加： 维数灾难。 </p>
<p><img src="https://i.imgur.com/Tlka5WK.png" alt=""></p>
<h2 id="3-4-线性判别函数的几何性质"><a href="#3-4-线性判别函数的几何性质" class="headerlink" title="3.4 线性判别函数的几何性质"></a>3.4 线性判别函数的几何性质</h2><p>略</p>
<h2 id="3-5-感知器算法"><a href="#3-5-感知器算法" class="headerlink" title="3.5 感知器算法"></a>3.5 感知器算法</h2><p>对于线性判别函数，当模式的维数已知时判别函数的形式实际上就已经定了下来，如：</p>
<p>二维: $X=(x_1,x_2)^T, d(X)=w_1x_1+w_2x_2+w_3$</p>
<p>三维： $X=(x_1,x_2，x_3)^T, d(X)=w_1x_1+w_2x_2+w_3x_3+w_4$</p>
<p>剩下的工作就是确定权重向量，只要求出权重向量，分类器的设计即告成功。</p>
<h3 id="算法描述"><a href="#算法描述" class="headerlink" title="算法描述"></a>算法描述</h3><p><img src="https://i.imgur.com/HdQnVrQ.png" alt=""></p>
<h3 id="收敛性"><a href="#收敛性" class="headerlink" title="收敛性"></a>收敛性</h3><p>如果经过算法的有限次迭代运算后，求除了一个使训练集中所有样本都能正确分离的$W$,则称算法是收敛的。可以证明感知器算法是收敛的。对于感知器算法，只要模式是线性可分的，就可以在有限的迭代步数内求出权重向量的解。</p>
<h2 id="3-6-梯度法"><a href="#3-6-梯度法" class="headerlink" title="3.6 梯度法"></a>3.6 梯度法</h2><h2 id="3-7-最小平方误差算法"><a href="#3-7-最小平方误差算法" class="headerlink" title="3.7 最小平方误差算法"></a>3.7 最小平方误差算法</h2><p>感知器算法、梯度算法和固定增量算法或其他类似算法，只有当被分类模式可分离是才收敛，在不可分的情况下，算法会来回摆动，始终不收敛。另一方面，在训练样本较多的情况下，即使模式类线性可分的，也不可能事先算出达到收敛时所需的迭代步数。很难判断操作不收敛的原因是由于迭代过程收敛的缓慢还是由于模式本身就线性不可分。</p>
<p>最小平方误差（LMSE）算法的推导利用了梯度的概念，他除了对线性可分的模式类收敛，对线性不可分的情况也可以在算法的迭代过程中明确地指示出来。</p>
<h3 id="1-分类器的不等式方程"><a href="#1-分类器的不等式方程" class="headerlink" title="1. 分类器的不等式方程"></a>1. 分类器的不等式方程</h3><p>两类分类问题的解相当于求一组线性不等式的解。如果给出分别属于$w_1,w_2$两个模式的训练样本集$\lbrace X_i,i=1,2,\dots,N\rbrace$，就可以求出权重向量$W$，它们的性质满足：</p>
<p>$W^TX_i &gt; 0$</p>
<p>则上式可以分开写为：</p>
<p><img src="https://i.imgur.com/OMAhPvH.png" alt=""></p>
<p>感知器算法就是通过解不等式组求得的W，如果模式是线性可分的，则X的每一个$(n+1) \times (n+1)$阶子矩阵的都等于$(n+1)$。</p>
<h3 id="2-LMSE算法"><a href="#2-LMSE算法" class="headerlink" title="2. LMSE算法"></a>2. LMSE算法</h3><h4 id="原理"><a href="#原理" class="headerlink" title="原理"></a>原理</h4><p>LMSE算法把满足$XW&gt;0$的求解，改为满足：</p>
<p>$XW=B$</p>
<p>的求解，式中$B=(b_1,b_2,\dots,b_n)^T$是各分离均为正值的矢量。因此该式于$XW&gt;0$是等价的。</p>
<p>在方程组中，方程的个数多余未知数个数时，也就是行数大于列数时，通常没有精确解存在，称为<b>矛盾方程组，一般求解近似解。</b></p>
<p>在模式识别中，训练样本数$N$总是大于模式的维数$n$，因此上式中方程的个数大于未知数$W$分量的个数，是矛盾方程组，只能求近似解，方法是求满足：</p>
<p>$||XW^{\ast}-B|| = 极小$</p>
<p>的$W^{\ast}$，$W^{\ast}$称为最小二乘近似解，也称为最优解。LMSE算法的出发点就是选择一个准则函数$J$，使得准则函数最小，$XW=B$可以得到最小二乘近似解。依据这种思路，可将LMSE算法的准则函数定义为:</p>
<p>$J(W,X,B)=\frac{1}{2}||XW-B||^2$</p>
<p><img src="https://i.imgur.com/x6Nlep4.png" alt=""></p>
<p>准则函数可继续写成：</p>
<p>$J(W,X,B)=\frac{1}{2}||XW-B||^2=\frac{1}{2}\sum_{i=1}^N(W^TX_i-b_i)^2$</p>
<p>准则函数的值等于$W^TX_i$与$b_i$误差的平方之和，我们的目标是使这个误差的平方的最小化，由此称之为最小平方误差算法。</p>
<h4 id="算法描述-1"><a href="#算法描述-1" class="headerlink" title="算法描述"></a>算法描述</h4><p>1、 将$N$个分属于$w_1$和$w_2$类的$n$维模式样本写成增广形式，将属于$w_2$的训练样本乘以-1，写出规范化增广样本矩阵$X$。</p>
<p>2、 求$X$得伪逆矩阵$X^{\ast}=(X^TX)^{-1}X^T$。</p>
<p>3、 设置初值$c$和$B(1)$，$c$为正得校验增量，$B(1)$的各分量大于零，括号中数字代表迭代次数$k=1$，开始迭代：</p>
<p>计算$W(1)=X^{\ast}B(1)$….</p>
<p>4、 计算$e(k)=XW(k)-B(k)$，进行可分性判别。</p>
<p>如果$e(k)=0$，模式类线性可分，解为$W(k)$，算法结束。</p>
<p>如果$e(k)&gt;0$，模式类线性可分，有界。若进入第5步继续迭代，可是$e(k) \rightarrow 0$，得到最优解。</p>
<p>如果$e(k)&lt;0$，停止迭代，检查$XW(k)$，若$XW(k)&gt;0$，有解；否则无解，算法结束。</p>
<p>若不是上述任一种情况，说明$e(k)$的各分量值有正有负，进入第5步：</p>
<p>5、 计算$W(k+1)$和$B(k+1)$。</p>
<p>方法1：分别计算$W(k+1)=W(k)+cX^{\ast}$和$B(k+1)=B(k)+c[e(k)+|e(k)|]$</p>
<p>方法2：先计算$B(k+1)=B(k)+c[e(k)+|e(k)|]$，再计算$W(k+1)=X^{\ast}B(k=1)$。</p>
<p>迭代次数$k$加1，返回第4步。</p>

      
    </div>
    
    
    

    
      <div>
        <div id="wechat_subscriber" style="display: block; padding: 10px 0; margin: 20px auto; width: 100%; text-align: center">
    <img id="wechat_subscriber_qcode" src="/images/wechat-qcode.jpg" alt="zxp wechat" style="width: 200px; max-width: 100%;"/>
    <div>欢迎关注微信公众号！</div>
</div>

      </div>
    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div></div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="/images/WeChatpay.jpg" alt="zxp 微信支付"/>
        <p>微信支付</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="/images/Alipay.jpg" alt="zxp 支付宝"/>
        <p>支付宝</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    
      <div>
        <ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者：</strong>
    zxp
  </li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="https://zxpgo.github.io/2018/11/08/模式识别(三)--判别函数及几何分类法/" title="模式识别(三)--判别函数及几何分类法">https://zxpgo.github.io/2018/11/08/模式识别(三)--判别函数及几何分类法/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>
    本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/3.0/" rel="external nofollow" target="_blank">CC BY-NC-SA 3.0</a> 许可协议。转载请注明出处！
  </li>
</ul>

      </div>
    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tag/模式识别/" rel="tag"># 模式识别</a>
          
        </div>
      

      
      
        <div class="post-widgets">
        

        

        
          
          <div id="needsharebutton-postbottom">
            <span class="btn">
              <i class="fa fa-share-alt" aria-hidden="true"></i>
            </span>
          </div>
        
        </div>
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2018/11/08/Intent和Activity/" rel="next" title="Intent和Activity">
                <i class="fa fa-chevron-left"></i> Intent和Activity
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2018/11/09/Java数组、列表、循环和自定义类/" rel="prev" title="Java数组、列表、循环和自定义类">
                Java数组、列表、循环和自定义类 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
      <div id="lv-container" data-id="city" data-uid="MTAyMC8zODgxNC8xNTM0Mg=="></div>
    </div>

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/images/avatar.gif"
                alt="zxp" />
            
              <p class="site-author-name" itemprop="name">zxp</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">176</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">16</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">48</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          
            <div class="feed-link motion-element">
              <a href="/atom.xml" rel="alternate">
                <i class="fa fa-rss"></i>
                RSS
              </a>
            </div>
          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://blog.csdn.net/qq_25774883" target="_blank" title="CSDN">
                      
                        <i class="fa fa-fw fa-globe"></i>CSDN</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/zxpgo/zxpgo" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-globe"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://www.linkedin.com/feed/" target="_blank" title="LinkedIn">
                      
                        <i class="fa fa-fw fa-globe"></i>LinkedIn</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="1165772354@qq.com" target="_blank" title="E-Mail">
                      
                        <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  </span>
                
            </div>
          

          
          

          
          
            <div class="links-of-blogroll motion-element links-of-blogroll-inline">
              <div class="links-of-blogroll-title">
                <i class="fa  fa-fw fa-link"></i>
                友情链接
              </div>
              <ul class="links-of-blogroll-list">
                
                  <li class="links-of-blogroll-item">
                    <a href="http://theme-next.iissnan.com" title="Next主题" target="_blank">Next主题</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://blog.rexking6.top" title="青爷博客" target="_blank">青爷博客</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://me.csdn.net/download/qq_25774883" title="CSDN下载" target="_blank">CSDN下载</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.livere.com/" title="来必力" target="_blank">来必力</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://tongji.baidu.com/web/welcome/login" title="百度统计" target="_blank">百度统计</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://leancloud.cn/" title="LeanCloud" target="_blank">LeanCloud</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://ibruce.info/2015/04/04/busuanzi/" title="不蒜子" target="_blank">不蒜子</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://leetcode-cn.com/" title="LeetCode" target="_blank">LeetCode</a>
                  </li>
                
              </ul>
            </div>
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#3-1-判别函数"><span class="nav-number">1.</span> <span class="nav-text">3.1 判别函数</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-2-线性判别函数"><span class="nav-number">2.</span> <span class="nav-text">3.2 线性判别函数</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#3-2-1-线性判别函数的一般形式"><span class="nav-number">2.1.</span> <span class="nav-text">3.2.1 线性判别函数的一般形式</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-2-1-线性判别函数的性质"><span class="nav-number">2.2.</span> <span class="nav-text">3.2.1 线性判别函数的性质</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#1-两类情况"><span class="nav-number">2.2.1.</span> <span class="nav-text">1.两类情况</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-多类情况"><span class="nav-number">2.2.2.</span> <span class="nav-text">2.多类情况</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#w-i-bar-w-i-两分法"><span class="nav-number">2.2.2.1.</span> <span class="nav-text">$w_i/\bar{w_i}$两分法</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#w-i-w-j-两分法"><span class="nav-number">2.2.2.2.</span> <span class="nav-text">$w_i/w_j$两分法</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#w-i-w-j-两分法特例"><span class="nav-number">2.2.3.</span> <span class="nav-text">$w_i/w_j$两分法特例</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-3-广义线性判别函数"><span class="nav-number">3.</span> <span class="nav-text">3.3 广义线性判别函数</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-非线性多项式函数"><span class="nav-number">3.1.</span> <span class="nav-text">1. 非线性多项式函数</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-4-线性判别函数的几何性质"><span class="nav-number">4.</span> <span class="nav-text">3.4 线性判别函数的几何性质</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-5-感知器算法"><span class="nav-number">5.</span> <span class="nav-text">3.5 感知器算法</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#算法描述"><span class="nav-number">5.1.</span> <span class="nav-text">算法描述</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#收敛性"><span class="nav-number">5.2.</span> <span class="nav-text">收敛性</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-6-梯度法"><span class="nav-number">6.</span> <span class="nav-text">3.6 梯度法</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-7-最小平方误差算法"><span class="nav-number">7.</span> <span class="nav-text">3.7 最小平方误差算法</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-分类器的不等式方程"><span class="nav-number">7.1.</span> <span class="nav-text">1. 分类器的不等式方程</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-LMSE算法"><span class="nav-number">7.2.</span> <span class="nav-text">2. LMSE算法</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#原理"><span class="nav-number">7.2.1.</span> <span class="nav-text">原理</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#算法描述-1"><span class="nav-number">7.2.2.</span> <span class="nav-text">算法描述</span></a></li></ol></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div>
<script async src="https//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<i class="fa fa-user-md"></i><span id="busuanzi_container_site_pv" style='display:none'>
    本站总访问量 <span id="busuanzi_value_site_pv"></span> 
    <span class="post-meta-divider">|</span>
</span>
<span id="busuanzi_container_site_uv" style='display:none'>
    访问人数 <span id="busuanzi_value_site_uv"></span>
</span>
</div>


<script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>

<div class="copyright">&copy; 2018-8 &mdash; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-"></i> Power by 
  </span>
  <span class="author" itemprop="copyrightHolder">zxp</span>
  
  
</div>









        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    
      <div id="needsharebutton-float">
        <span class="btn">
          <i class="fa fa-share-alt" aria-hidden="true"></i>
        </span>
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  




  
  <div id="lv-container" data-uid="MTAyMC8zODgxNC8xNTM0Mg==">
    <script type="text/javascript">
      (function(d, s) {
        var j, e = d.getElementsByTagName(s)[0];
        if (typeof LivereTower === 'function') { return; }
        j = d.createElement(s);
        j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
        j.async = true;
        e.parentNode.insertBefore(j, e);
      })(document, 'script');
    </script>
	</div>
  











  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.4.js"></script>
  <script>AV.initialize("2AyV3DKioBSdoryrFLRohzjB-gzGzoHsz", "XynedcHyJCVCrTfbD4yYnodo");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  

  
<script>
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>


  
  
  
  <link rel="stylesheet" href="/lib/needsharebutton/needsharebutton.css">

  
  
  <script src="/lib/needsharebutton/needsharebutton.js"></script>

  <script>
    
      pbOptions = {};
      
          pbOptions.iconStyle = "default";
      
          pbOptions.boxForm = "vertical";
      
          pbOptions.position = "top";
      
          pbOptions.networks = "Weibo,Wechat,Douban,QQZone,Twitter,Facebook";
      
      new needShareButton('#needsharebutton-postbottom', pbOptions);
    
    
      flOptions = {};
      
          flOptions.iconStyle = "box";
      
          flOptions.boxForm = "horizontal";
      
          flOptions.position = "middleRight";
      
          flOptions.networks = "Weibo,Wechat,Douban,QQZone,Twitter,Facebook";
      
      new needShareButton('#needsharebutton-float', flOptions);
    
  </script>

  

  
  
    <script type="text/x-mathjax-config">
      MathJax.Hub.Config({
        tex2jax: {
          inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
          processEscapes: true,
          skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
        }
      });
    </script>

    <script type="text/x-mathjax-config">
      MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax(), i;
        for (i=0; i < all.length; i += 1) {
          all[i].SourceElement().parentNode.className += ' has-jax';
        }
      });
    </script>
    <script type="text/javascript" src="//cdn.bootcss.com/mathjax/2.7.1/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
  


  
  <script type="text/javascript" src="/js/src/js.cookie.js?v=5.1.4"></script>
  <script type="text/javascript" src="/js/src/scroll-cookie.js?v=5.1.4"></script>


  
  <script type="text/javascript" src="/js/src/exturl.js?v=5.1.4"></script>


  
  
  	 <!-- custom analytics part create by xiamo -->
<script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.1.js"></script>
<script>AV.initialize("2AyV3DKioBSdoryrFLRohzjB-gzGzoHsz", "XynedcHyJCVCrTfbD4yYnodo");</script>
<script>
function showTime(Counter) {
	var query = new AV.Query(Counter);
	$(".leancloud_visitors").each(function() {
		var url = $(this).attr("id").trim();
		query.equalTo("url", url);
		query.find({
			success: function(results) {
				if (results.length == 0) {
					var content = $(document.getElementById(url)).text() + ' 0';
					$(document.getElementById(url)).text(content);
					return;
				}
				for (var i = 0; i < results.length; i++) {
					var object = results[i];
					var content = $(document.getElementById(url)).text() + ' ' + object.get('time');
					$(document.getElementById(url)).text(content);
				}
			}
		});

	});
}

</script>
  
</body>
</html>
